/* AboutDialog.cs
 * 
 * PROGRAMMER:    Jeffrey T. Darlington
 * DATE:          September 17, 2009
 * PROJECT:       Cryptnos
 * .NET VERSION:  2.0
 * REQUIRES:      (None)
 * REQUIRED BY:   Form1
 * 
 * The About dialog for Cryptnos.  Nothing fancy here.  It just takes a version string and a
 * string containing the copyright information.
 * 
 * UPDATES FOR 1.2.2: Added Help button that launched the default browser with the HTML help
 * file.
 * 
 * This program is Copyright 2011, Jeffrey T. Darlington.
 * E-mail:  jeff@gpf-comics.com
 * Web:     http://www.gpf-comics.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See theGNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace com.gpfcomics.Cryptnos
{
    public partial class AboutDialog : Form
    {
        /// <summary>
        /// The AboutDialog constructor
        /// </summary>
        /// <param name="version">The version string generated by the parent</param>
        /// <param name="copyright">The copyright string generated by the parent</param>
        /// <param name="showTooltips">A boolean value specifying whether or not to show
        /// tooltip help.</param>
        /// <param name="keepOnTop">Keep Cryptnos windows on top of other windows</param>
        public AboutDialog(string versionLong, string versionShort, string copyright,
            bool showTooltips, bool keepOnTop)
        {
            InitializeComponent();
            // Populate the title bar, version and copyright labels with information
            // provided to us by the parent.
            Text = "About " + versionShort;
            lblVersion.Text = versionLong;
            lblCopyright.Text = copyright;
            // Should we show tooltip help?
            toolTip1.Active = showTooltips;
            TopMost = keepOnTop;
        }

        /// <summary>
        ///  What to do when the OK button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        /// <summary>
        /// What to do when the Hep button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHelp_Click(object sender, EventArgs e)
        {
            // The HTML help file sits in the same folder as the Cryptnos executable.
            // So to get the location of the EXE and append the help file name to the
            // folder's path.
            FileInfo mainExePath = new FileInfo(Application.ExecutablePath);
            string helpIndex = mainExePath.DirectoryName + 
                Char.ToString(System.IO.Path.DirectorySeparatorChar) +
                "help.html";
            // The file should exist, but just in case it doesn't:
            if ((new FileInfo(helpIndex)).Exists)
            {
                // Try to launch the default browser.  We'll pass the path to the HTML file
                // to the system and let it handle what browser to open.  Whatever is
                // associated with HTML files should be launched.  However, just in case
                // something blows up, we'll include this in a try/catch and display an
                // error if it fails.
                try { System.Diagnostics.Process.Start(helpIndex); }
                catch
                {
                    MessageBox.Show("I was unable to launch your default browser to display " +
                        "the Cryptnos help file. Please use the shortcut icon in the Start " +
                        "menu instead.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            // If the help files can't be found, complain:
            else
            {
                MessageBox.Show("The Cryptnos HTML help file could not be found. Please " +
                    "reinstall Cryptnos.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}